//
//  RBCompeRecomViewCell.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/12.
//

#import "RBCompeRecomViewCell.h"
#import "RBCompeRecomColleViewCell.h"
#import "RBCompeRecommendModel.h"

@interface RBCompeRecomViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(strong,nonatomic)UIView *bgView;
@property(strong,nonatomic)UICollectionView *collectionView;
@end
@implementation RBCompeRecomViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self rb_initViewUI];
        [self layoutIfNeeded];
    }
    return self;
}
-(void)rb_initViewUI{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.collectionView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(0);
    }];
}

-(void)setHotRecomArray:(NSMutableArray *)hotRecomArray{
    _hotRecomArray=hotRecomArray;
    [self layoutIfNeeded];
    [self.collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.hotRecomArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    RBCompeRecomColleViewCell *compeRecomColleViewCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RBCompeRecomColleViewCell" forIndexPath:indexPath];
    compeRecomColleViewCell.model = self.hotRecomArray[indexPath.item];
    return compeRecomColleViewCell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    ChtyChatGamesChooiceVCModel *model = self.recomCompArray[indexPath.row];
//    ChtyCompDetailViewController *compDetailVc = [[ChtyCompDetailViewController alloc] init];
//    compDetailVc.sportId = model.sportId;
//    compDetailVc.matchId = model.matchId;
//    [[ChtyTool DSJY_getCurrentViewController].navigationController pushViewController:compDetailVc animated:YES];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(RBScaleWidth(180),RBScaleWidth(112));
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0,RBScaleWidth(10),0,RBScaleWidth(10));
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return RBScaleWidth(10);
}
-  (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}
- (UIView *)bgView{
    if(_bgView==nil){
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor clearColor];
    }
    return _bgView;
}
-(UICollectionView *)collectionView{
    if(!_collectionView){
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.pagingEnabled = YES;
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        [_collectionView registerClass:[RBCompeRecomColleViewCell class] forCellWithReuseIdentifier:NSStringFromClass([RBCompeRecomColleViewCell class])];
    }
    return _collectionView;
}

@end
